home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / belltest.lzh / BELLTEST.C next >
C/C++ Source or Header  |  1990-04-05  |  5KB  |  282 lines

  1. #include <aes.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <tos.h>
  5. #include <string.h>
  6. #include <mydefs.h>
  7. #include "strins.c"
  8. #include "belltest.h"
  9. #include "belltstr.c"
  10.  
  11. void mess(char *c)
  12.     {
  13.     char     a[40];
  14.     
  15.     graf_mouse(ARROW,0);
  16.     strcpy(a,"[3][");
  17.     strcat(a,c);
  18.     strcat(a,"][OK]");
  19.     form_alert(1,a);
  20.     graf_mouse(POINT_HAND,0);
  21.     }
  22.  
  23. /*******************************
  24.     Select a file
  25. *******************************/
  26. int fileselect(
  27.     char     *s,
  28.     char    *ext)
  29.     {
  30.     char    p[64];
  31.     int        n;
  32.     int        drv;
  33.  
  34.     drv = Dgetdrv();
  35.     Dgetpath(p,0);
  36.     if (p[0] != '\\')    strinc(p,0,'\\');
  37.     strins(p,0,"A:");
  38.     while (drv > 0)
  39.         {
  40.         --drv;
  41.         ++p[0];
  42.         }
  43.     if (p[strlen(p)-1] != '\\')    strcat(p,"\\");
  44.     strcat(p,ext);
  45.     graf_mouse(ARROW,0);
  46.     fsel_input(p,s,&n);
  47.     graf_mouse(POINT_HAND,0);
  48.     if (strrchr(p,'\\') != strchr(p,'\\'))
  49.         *(strrchr(p,'\\')) = 0x0;
  50.     else
  51.         *(strrchr(p,'\\')+1) = 0x0;
  52.     while (*p > 'A')
  53.         {
  54.         --p[0];
  55.         ++drv;
  56.         }
  57.     Dsetdrv(drv);
  58.     Dsetpath(p+2);
  59.     return(n);
  60.     }
  61.  
  62. void dial_draw(
  63.     int box_ind,
  64.     int    obj    )
  65.     {
  66.     int        x1,y1;
  67.     OBJECT    *redraw;
  68.     
  69.     redraw = &rs_object[rs_trloc[box_ind]+obj];
  70.     objc_offset(rs_trindex[box_ind],obj,&x1,&y1);
  71.     objc_draw(rs_trindex[box_ind],0,10,x1,y1,redraw->ob_width,redraw->ob_height);
  72.     }
  73.  
  74.  
  75. void erase_dialog(
  76.     int    x,
  77.     int    y,
  78.     int    w,
  79.     int    h    )
  80.     {
  81.     int sx,sy;
  82.     sx=x+(w/2);
  83.     sy=y+(h/2);
  84.     form_dial(FMD_SHRINK,sx,sy,0,0,x,y,w,h);
  85.     form_dial(FMD_FINISH,sx,sy,0,0,x,y,w,h);
  86.     }
  87.  
  88. void draw_dialog(
  89.     int        box_ind,
  90.     int        *x,
  91.     int        *y,
  92.     int        *w,
  93.     int        *h,
  94.     char    draw    )
  95.     {
  96.     int        sx,sy;
  97.     
  98.     form_center(rs_trindex[box_ind],x,y,w,h);
  99.     sx=*x+(*w/2);
  100.     sy=*y+(*h/2);
  101.     
  102.     form_dial(FMD_START,sx,sy,0,0,*x,*y,*w,*h); 
  103.     form_dial(FMD_GROW,sx,sy,0,0,*x,*y,*w,*h);
  104.     if (draw) objc_draw(rs_trindex[box_ind],0,10,*x,*y,*w,*h);
  105.     }
  106.  
  107. void unselect(
  108.     int box,
  109.     int item)
  110.     {
  111.     rs_object[rs_trloc[box]+item].ob_state &= UNSELECT;
  112.     }
  113.  
  114. int selected(
  115.     int box,
  116.     int item)
  117.     {
  118.     return(rs_object[rs_trloc[box]+item].ob_state & SELECTED);
  119.     }
  120.  
  121. int    exit_dialog(
  122.     int box_ind,
  123.     int    x,
  124.     int    y,
  125.     int    w,
  126.     int    h,
  127.     int    draw    )
  128.     {
  129.     int     e;
  130.     
  131.     if (draw) objc_draw(rs_trindex[box_ind],0,10,x,y,w,h);
  132.     e = form_do(rs_trindex[box_ind],0);
  133.     unselect(box_ind,e);
  134.     dial_draw(box_ind,e);
  135.     return(e);
  136.     }
  137.  
  138. void putspeed(char c)
  139.     {
  140.     int i;
  141.  
  142.     for(i=8;i<12;i++)
  143.         if ((rs_object[i].ob_state & SELECTED)!=0)
  144.             {
  145.             if (c != *rs_object[i].ob_spec.free_string)
  146.                 rs_object[i].ob_state &= UNSELECT;
  147.             }
  148.         else
  149.             {
  150.             if (c == *rs_object[i].ob_spec.free_string)
  151.                 rs_object[i].ob_state |= SELECTED;
  152.             }
  153.     }
  154.  
  155.  
  156. char getspeed(void)
  157.     {
  158.     int i;
  159.     char c='3';
  160.  
  161.     for(i=8;i<12;i++)
  162.         if ((rs_object[i].ob_state & SELECTED)!=0)
  163.             c = *rs_object[i].ob_spec.free_string;
  164.     return(c);
  165.     }
  166.  
  167. int main()
  168.     {
  169.     int         x,y,w,h;
  170.     int         choice,flag,fd;
  171.     static char *ext="*.SND";
  172.     static COMMAND line={0,"0 TESTTEST.SND"};
  173.     char         *buf,*file;
  174.     DTA            *dta;
  175.     long        l;
  176.     static char *newb="\0C:\\AUTO\\NEWBELL.PRG";
  177.     long         *screen;
  178.     long        cnt;
  179.     long        *scrbuf;
  180.  
  181.     /*      INITIALIZE GEM              */
  182.     appl_init();
  183.        fix_objects();
  184.     
  185.     /*      APPLICATION ROUTINES        */
  186.     graf_mouse(POINT_HAND,0);
  187.  
  188.     flag=0;
  189.     if (Fsfirst("NEWBELL.PRG",0)<0)
  190.         {
  191.         ++flag;
  192.         if (Fsfirst("C:\\AUTO\\NEWBELL.PRG",0)<0)
  193.             {
  194.             ++flag;
  195.             if (Fsfirst("A:\\AUTO\\NEWBELL.PRG",0)<0)
  196.                 {
  197.                 mess("NEWBELL.PRG NOT FOUND");
  198.                 ++flag;
  199.                 }
  200.             else
  201.                 strcpy(newb,"A:\\AUTO\\NEWBELL.PRG");
  202.             }
  203.         else
  204.             strcpy(newb,"C:\\AUTO\\NEWBELL.PRG");
  205.         }
  206.     else
  207.         strcpy(newb,"NEWBELL.PRG");
  208.  
  209.     if (flag!=3)
  210.         {
  211.         draw_dialog(MAINDIAL,&x,&y,&w,&h,1);
  212.         file = line.command_tail+2;
  213.         buf = NULL;
  214.         choice=0;
  215.         while(choice!=MAINQUIT)
  216.             {
  217.             choice = exit_dialog(MAINDIAL,x,y,w,h,0);
  218.             switch(choice)
  219.                 {
  220.                 case MAINLOAD:
  221.                     erase_dialog(x,y,w,h);
  222.                     if (fileselect(file,ext))
  223.                         {
  224.                         if (Fsfirst(file,0)>=0)
  225.                             {
  226.                             dta = Fgetdta();
  227.                             l = dta->d_length;
  228.                             if (buf!=NULL)
  229.                                 free(buf);
  230.                             buf=malloc(l+16);
  231.                             fd=Fopen(file,READ);
  232.                             Fread(fd,l,buf);
  233.                             Fclose(fd);
  234.                             if ((*buf<6)&&(*buf>0))
  235.                                 putspeed(*buf+'0');
  236.                             }
  237.                         }
  238.                     draw_dialog(MAINDIAL,&x,&y,&w,&h,1);
  239.                     break;
  240.                 case MAINSAVE:
  241.                     break;
  242.                 case MAINPLAY:
  243.                     scrbuf=malloc(32768L);
  244.                     if (scrbuf!=NULL)
  245.                         {
  246.                         graf_mouse(M_OFF,0);
  247.                         screen=(long *)Physbase();
  248.                         for(cnt=0;cnt<8192L;cnt++)
  249.                             {
  250.                             *(scrbuf+cnt)=*(screen+cnt);
  251.                             *(screen+cnt)=0L;
  252.                             }
  253.                         }
  254.                     line.length = strlen(line.command_tail);
  255.                     *line.command_tail = getspeed();
  256.                     *buf = getspeed() - '0';
  257.                     fd=Fopen(file,WRITE);
  258.                     Fwrite(fd,l,buf);
  259.                     Fclose(fd);
  260.                     Pexec(0,newb,&line,NULL);
  261.                     if (scrbuf!=NULL)
  262.                         {
  263.                         for(cnt=0;cnt<8192L;cnt++)
  264.                             *(screen+cnt)=*(scrbuf+cnt);
  265.                         free(scrbuf);
  266.                         graf_mouse(M_ON,0);
  267.                         graf_mouse(POINT_HAND,0);
  268.                         }
  269.                     break;
  270.                 case MAINQUIT:
  271.                     break;
  272.                 }
  273.             }
  274.         erase_dialog(x,y,w,h);
  275.         if (buf!=NULL)
  276.             free(buf);
  277.         }
  278.     graf_mouse(ARROW,0);
  279.     appl_exit();
  280.     return(0);
  281.     }
  282.